const express = require('express');
const path = require('path');
const app = express();
const port = 8080;

// 设置静态文件目录（如果需要）
app.use(express.static('public'));

// 文件下载路由
app.get('/download/:type', (req, res) => {
    const fileType = req.params.type;
    let fileName, filePath;

    switch(fileType) {
        case 'word':
            fileName = 'word操作题.docx';
            filePath = path.join(__dirname, 'files', fileName);
            break;
        case 'excel':
            fileName = 'Excel操作题.xlsx';
            filePath = path.join(__dirname, 'files', fileName);
            break;
        case 'ppt':
            fileName = 'PPT操作题.pptx';
            filePath = path.join(__dirname, 'files', fileName);
            break;
        case 'simulation':
            fileName = '全真模拟.zip';
            filePath = path.join(__dirname, 'files', fileName);
            break;
        default:
            return res.status(404).send('File not found');
    }

    res.download(filePath, fileName, (err) => {
        if (err) {
            console.error('Download error:', err);
            res.status(404).send('File not found');
        }
    });
});

app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});